﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading;
using Crawler.Abot;
using Crawler.ApplicationServices;
using Crawler.ContentProcessors;
using Crawler.DataServices;
using Crawler.DataServices.Repositories;
using Crawler.Domain;
using Crawler.DomainServices;
using Crawler.Downloaders;
using Crawler.Infrastructure;
using Crawler.Infrastructure.ApplicationServices;
using StructureMap;
using StructureMap.Configuration.DSL;

namespace ConsoleApplication1
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			IoCRegistrator.Register(new List<Registry>
			{
				new AbotRegistry(),
				new ClientRegistry(),
				new ContentProcessorsRegistry(),
				new DomainServicesRegistry(),
				new DataServicesRegistry(),
				new ApplicationServicesRegistry() ,
				new DownloadersRegistry()
			});

			//PrintIP();

			Console.WriteLine("Options:");
			Console.WriteLine("1-Crawl Content");
			Console.WriteLine("2-Proccess Session Content");
			var opt=Console.ReadLine();
			switch (opt)
			{
				case "1":
					Crawl();
					break;
				case "2":
					ProccessSessionContent();
					break;
			}

			Console.WriteLine("Press key to finish..");
			Console.ReadKey();
		}

		private static void ProccessSessionContent()
		{
			Console.WriteLine("Type SessionId:");
			var sessionId = Console.ReadLine();
			var processor = ObjectFactory.GetInstance<ITorrentContentProcessor>();

			processor.Start(sessionId, new CancellationTokenSource());
		}

		private static void Crawl()
		{
			var crawler = ObjectFactory.GetInstance<ITorrentCrawler>();
			var cts = new CancellationTokenSource();
			crawler.Start(TorrentSource.YifyTorrent, cts);
		}

		private static void PrintIP()
		{
			var h = ObjectFactory.GetInstance<IRequestsHelper>();
			Console.WriteLine(h.GetPageHtmlText("http://icanhazip.com/"));

			Console.ReadLine();
		}

	}



}